package com.bc004346.travelus;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;

import com.bc004346.travelus.fragment.TripListFragment;
import com.bc004346.travelus.model.abstracts.CustomListActivity;
import com.bc004346.travelus.model.domain.DayTrip;
import com.bc004346.travelus.services.TripMeService;
import com.bc004346.travelus.utility.NotificationHelper;
import com.bc004346.travelus.utility.Utility;

import java.util.ArrayList;

/**
 * Created by Renats on 12/2/2014.
 * Shows flight pairs
 */
public class TripMeFlightListActivity extends CustomListActivity {

    private TripListFragment mFragment = new TripListFragment();
    private ArrayList<DayTrip> mTrips = new ArrayList<DayTrip>();

    @Override
    protected Fragment getFragment() {
        return mFragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        try {
            NotificationHelper.removeNotification(this, TripMeService.NOTIFICATION_ID);
            //noinspection unchecked
            mTrips = (ArrayList<DayTrip>) getIntent().getSerializableExtra(TripMeService.TRIP_ME_INTENT);
            if (mTrips != null && mTrips.size() > 0)
                setTitle(String.format("Day Trips for %s", Utility.DAY_DATE.format(mTrips.get(0).getOutboundFlight().getDeparture())));
            else
                setTitle("No good day trip options :(");

            mSwipeRefresh.setEnabled(false);
            mSwipeRefresh.setRefreshing(false);
            mTopProgressBar.setVisibility(View.INVISIBLE);
            refresh();
        } catch (Exception e) {
            Utility.log(e, this);
        }
    }

    @Override
    public void refresh() {
        mFragment.refresh(mTrips);
        mSwipeRefresh.setRefreshing(false);
        mTopProgressBar.setVisibility(View.INVISIBLE);
    }
}
